﻿@model SiteImportNativeModel

@{
	ViewBag.Title = "Site Import";
}


@if (!String.IsNullOrEmpty(Model.Message)) {
	<fieldset style="width: 90%;">
		<legend>
			<label>
				Import Summary
			</label>
		</legend>
		<div id="divSiteLoadSummary">
			<ul>
				@Html.Raw(Model.Message)
			</ul>
		</div>
	</fieldset>
}

<script type="text/javascript">
	function cmsLoadImportAlert() {
		if ($('#divSiteLoadSummary ul li').length > 0) {
			var txt = $('#divSiteLoadSummary').html();
			cmsAlertModal(txt);
		}
	}

	$(document).ready(function () {
		cmsLoadImportAlert();
	});
</script>

@using (Html.BeginForm()) {
	@Html.AntiForgeryToken()

	@Html.HiddenFor(m => m.ImportID)
	@Html.HiddenFor(m => m.HasLoaded)

	<div style="display: none">
		<div id="formPrettyValidationSummary">
			@Html.ValidationSummary(true, "")
		</div>
	</div>

	<p>
		The below information (if checked) will be imported to the current site. You can always update the information after importing.
	</p>
	<div style="display: none" id="importMessage">
	</div>
	<fieldset style="width: 90%;">
		<legend>
			<label>
				Site Information
				@Html.CheckBoxFor(m => m.ImportSite)
				@Html.Partial("_displayErrorPopupButton")
			</label>
		</legend>
		<table style="width: 99%;">
			<tr>
				<td class="tablecaption" style="width: 200px;">
					Exported from CMS Version
				</td>
				<td>
					@Model.Site.CarrotCakeVersion
					@Html.HiddenFor(m => m.Site.CarrotCakeVersion)
				</td>
			</tr>
			<tr>
				<td class="tablecaption">
					Export Date
				</td>
				<td>
					@Model.Site.ExportDate
					@Html.HiddenFor(m => m.Site.ExportDate)
				</td>
			</tr>
			<tr>
				<td colspan="2">
					&nbsp;
				</td>
			</tr>
			<tr>
				<td class="tablecaption">
					Site Name
				</td>
				<td>
					@Model.Site.TheSite.SiteName
					@Html.HiddenFor(m => m.Site.TheSite.SiteName)
					@Html.HiddenFor(m => m.Site.TheSite.SiteID)
				</td>
			</tr>
			<tr>
				<td class="tablecaption">
					Site Description
				</td>
				<td>
					@Model.Site.TheSite.SiteTagline
					@Html.HiddenFor(m => m.Site.TheSite.SiteTagline)
				</td>
			</tr>
		</table>
		<table style="width: 99%;">
			<tr>
				<td>
					@Html.CheckBoxFor(m => m.CreateUsers)
					@*<input id="chkAuthors" type="checkbox" name="chkAuthors" checked="checked" />*@
					Uncheck this box if you do not want new user accounts to be created. Accounts will only be created if the username and email address have not
					already been used in this system. Password will be set according to normal reset values, and the user will have to request a new password by
					email to login. If this is unchecked and a matching account exists, the discovered user will be recorded as the content editor. If the user
					account does not exist, the current user will be recorded as the content editor.
				</td>
			</tr>
			<tr>
				<td>
					@Html.CheckBoxFor(m => m.MapUsers)
					@*<input id="chkMapAuthor" type="checkbox" name="chkMapAuthor" checked="checked" />*@
					Uncheck this box if you want all imported content to be recorded under the current user. This option trumps the account creation checkbox.
				</td>
			</tr>
		</table>
	</fieldset>
	<fieldset style="width: 90%;">
		<legend>
			<label>
				Comments
				@Html.CheckBoxFor(m => m.ImportComments)
				@Html.Partial("_displayErrorPopupButton")
			</label>
		</legend>
		<p>
			@String.Format(" {0} records", Model.Site.TheComments.Count)
		</p>
	</fieldset>
	<fieldset style="width: 90%;">
		<legend>
			<label>
				Pages
				@Html.CheckBoxFor(m => m.ImportPages)
				@Html.Partial("_displayErrorPopupButton")
			</label>
		</legend>
		<table>
			<tr>
				<td class="tablecaption">
					template:
				</td>
				<td>
					@Html.DropDownListFor(m => m.PageTemplate, new SelectList(Model.Templates, "TemplatePath", "Caption"))
				</td>
			</tr>
		</table>
		<p>
			@String.Format(" {0} records", Model.Site.TheContentPages.Count)
		</p>

		@{
	var pageGrid = CarrotWeb.CarrotWebGrid<ContentPage>(Model.Site.TheContentPages.Select(s => s.ThePage).OrderBy(s => s.NavOrder).ToList());

	pageGrid.TableAttributes = new { @class = "datatable" };
	pageGrid.THeadAttributes = new { @class = "tablehead" };
	pageGrid.EmptyDataTemplate = @<text><p> <b>No records found.</b> </p></text>;
	pageGrid.UseDataPage = false;
	pageGrid.ConfigName(Html.NameFor(x => Model.Site.TheContentPages));

	pageGrid
		.AddColumn(x => x.NavOrder, new CarrotGridColumn())
		.AddColumn(x => x.FileName, new CarrotGridColumn())
		.AddColumn(x => x.NavMenuText, new CarrotGridColumn())
		.AddColumn(x => x.CreateDate, new CarrotGridColumn { CellFormatString = "{0:M/d/yyyy}" })
		.AddColumn(x => x.PageActive, new CarrotGridBooleanImageColumn());

		@pageGrid.OutputHtmlBody()
		}

	</fieldset>
	<fieldset style="width: 90%;">
		<legend>
			<label>
				Blog Posts
				@Html.CheckBoxFor(m => m.ImportPosts)
				@Html.Partial("_displayErrorPopupButton")
			</label>
		</legend>
		<table>
			<tr>
				<td class="tablecaption">
					template:
				</td>
				<td>
					@Html.DropDownListFor(m => m.PostTemplate, new SelectList(Model.Templates, "TemplatePath", "Caption"))
				</td>
			</tr>
		</table>
		<p>
			@String.Format(" {0} records", Model.Site.TheBlogPages.Count)
		</p>
		@{
	var postGrid = CarrotWeb.CarrotWebGrid<ContentPage>(Model.Site.TheBlogPages.Select(s => s.ThePage).OrderByDescending(s => s.CreateDate).ToList());

	postGrid.TableAttributes = new { @class = "datatable" };
	postGrid.THeadAttributes = new { @class = "tablehead" };
	postGrid.EmptyDataTemplate = @<text><p> <b>No records found.</b> </p></text>;
	postGrid.UseDataPage = false;
	postGrid.ConfigName(Html.NameFor(x => Model.Site.TheBlogPages));

	postGrid
		.AddColumn(x => x.FileName, new CarrotGridColumn())
		.AddColumn(x => x.NavMenuText, new CarrotGridColumn())
		.AddColumn(x => x.CreateDate, new CarrotGridColumn { CellFormatString = "{0:M/d/yyyy}" })
		.AddColumn(x => x.PageActive, new CarrotGridBooleanImageColumn());

		@postGrid.OutputHtmlBody()
		}

	</fieldset>
	<fieldset style="width: 90%;">
		<legend>
			<label>
				Content Snippets
				@Html.CheckBoxFor(m => m.ImportSnippets)
				@Html.Partial("_displayErrorPopupButton")
			</label>
		</legend>
		<p>
			@String.Format(" {0} records", Model.Site.TheSnippets.Count)
		</p>
		@{
	var snipGrid = CarrotWeb.CarrotWebGrid<ContentSnippet>(Model.Site.TheSnippets.OrderByDescending(s => s.ContentSnippetName).ToList());

	snipGrid.TableAttributes = new { @class = "datatable" };
	snipGrid.THeadAttributes = new { @class = "tablehead" };
	snipGrid.EmptyDataTemplate = @<text><p> <b>No records found.</b> </p></text>;
	snipGrid.UseDataPage = false;
	snipGrid.ConfigName(Html.NameFor(x => Model.Site.TheContentPages));

	snipGrid
		.AddColumn(x => x.ContentSnippetSlug, new CarrotGridColumn())
		.AddColumn(x => x.ContentSnippetName, new CarrotGridColumn())
		.AddColumn(x => x.CreateDate, new CarrotGridColumn { CellFormatString = "{0:M/d/yyyy}" })
		.AddColumn(x => x.ContentSnippetActive, new CarrotGridBooleanImageColumn());

		@snipGrid.OutputHtmlBody()
		}
	</fieldset>
	<p>
		<input type="submit" name="btnSave" value="Apply Changes" id="btnSave" />
	</p>
}
